/*
    client 合集

    1,启动2个守护进程
        （1）c_client.js
        （2）c_opc.js
*/


var fork = require('child_process').fork;
var cpus = require('os').cpus();
var workers = {};
var appsPath = ['./route.js'];
var createWorker = function(appPath){
    var worker = fork(appPath);

    worker.on('exit',function(){
        console.log('worker:' + worker.pid + ' exited');
        delete workers[worker.pid];
        createWorker(appPath);
    });

    workers[worker.pid] = worker;
    console.log('create worker:' + worker.pid);
}
for (var i = appsPath.length - 1; i >= 0; i--) {
    createWorker(appsPath[i]);
};
process.on('exit',function(){
    for(var pid in workers){
        workers[pid].kill();
    }
})
